Imports System.Text

Public Class SUM_Database
    Private Const Q As String = Chr(34)

    Private mlDatabaseID As Long

    Private mbShowBlocks As Boolean = False
    Private mbShowConnect As Boolean = False
    Private mbShowSize As Boolean = False
    Private mbShowWaitStates As Boolean = False
    Private mbShowSchema As Boolean = False

    Private msBaseURL As String = ""

    Public Sub New( _
                ByVal sBaseURL As String, _
                ByVal lDatabaseID As Long)

        msBaseURL = sBaseURL
        mlDatabaseID = lDatabaseID
    End Sub

    Public Property DatabaseID() As Long
        Get
            Return mlDatabaseID
        End Get
        Set(ByVal value As Long)
            mlDatabaseID = value
        End Set
    End Property

    Public Property ShowBlocks() As Boolean
        Get
            Return mbShowBlocks
        End Get
        Set(ByVal value As Boolean)
            mbShowBlocks = value
        End Set
    End Property

    Public Property ShowConnect() As Boolean
        Get
            Return mbShowConnect
        End Get
        Set(ByVal value As Boolean)
            mbShowConnect = value
        End Set
    End Property

    Public Property ShowSize() As Boolean
        Get
            Return mbShowSize
        End Get
        Set(ByVal value As Boolean)
            mbShowSize = value
        End Set
    End Property

    Public Property ShowWaitStates() As Boolean
        Get
            Return mbShowWaitStates
        End Get
        Set(ByVal value As Boolean)
            mbShowWaitStates = value
        End Set
    End Property

    Public Property ShowSchema() As Boolean
        Get
            Return mbShowSchema
        End Get
        Set(ByVal value As Boolean)
            mbShowSchema = value
        End Set
    End Property

    Public Function Summerize() As String
        Dim oDatabase As New SQLAutoDocLib.Database(mlDatabaseID)
        oDatabase.Load()

        Dim oSum As New StringBuilder

        With oSum
            .Append("<style type=" & Q & "text/css" & Q & ">")
            .Append(" td {")
            .Append("   font-family: arial;")
            .Append("   font-size: 10px;")
            .Append(" }")
            .Append("</style>")

            .Append("<table style=" & Q & "width: 450px; border-collapse: collapse;" & Q & ">")
            .Append("<tr>")
            .Append("<td style=" & Q & "vertical-align: bottom; text-align: left; padding-left: 10px; font-size: 12px; font-weight: bold;" & Q & ">")
            .Append(oDatabase.Name)
            .Append("</td>")
            .Append("</tr>")
            .Append("<tr>")
            .Append("<td style=" & Q & "vertical-align: bottom; text-align: left; padding-left: 20px; font-size: 10px; font-weight: normal;" & Q & ">")
            .Append(oDatabase.Desc)
            .Append("</td>")
            .Append("</tr>")

            If mbShowSize = True Then
                '---Show Size summary for this database
                .Append("<tr>")
                .Append("<td style=" & Q & "padding-left: 20px; vertical-align: top; text-align: left;" & Q & ">")

                Dim oSum_Size As New SUM_Size(msBaseURL, mlDatabaseID)
                .Append(oSum_Size.Summerize)

                .Append("</td>")
                .Append("</tr>")
            End If

            If mbShowBlocks = True Then
                '---Show block summary for this database
                .Append("<tr>")
                .Append("<td style=" & Q & "padding-top: 20px; padding-left: 20px; vertical-align: top; text-align: left;" & Q & ">")

                Dim oSum_Blocks As New SUM_Blocks(msBaseURL, mlDatabaseID)
                .Append(oSum_Blocks.Summerize)

                .Append("</td>")
                .Append("</tr>")
            End If

            If mbShowConnect = True Then
                '---Show connection summary for this database
                .Append("<tr>")
                .Append("<td style=" & Q & "padding-top: 20px; padding-left: 20px; vertical-align: top; text-align: left;" & Q & ">")

                Dim oSum_Connect As New SUM_Connect(msBaseURL, mlDatabaseID)
                .Append(oSum_Connect.Summerize)

                .Append("</td>")
                .Append("</tr>")
            End If

            If mbShowWaitStates = True Then
                '---Show WaitState summary for this database
                .Append("<tr>")
                .Append("<td style=" & Q & "padding-top: 20px; padding-left: 20px; vertical-align: top; text-align: left;" & Q & ">")

                Dim oSum_WaitStates As New SUM_WaitStates(msBaseURL, mlDatabaseID)
                .Append(oSum_WaitStates.Summerize)

                .Append("</td>")
                .Append("</tr>")
            End If

            If mbShowSchema = True Then
                '---Show Schema summary for this database
                .Append("<tr>")
                .Append("<td style=" & Q & "padding-top: 20px; padding-left: 20px; vertical-align: top; text-align: left;" & Q & ">")

                Dim oSum_Schema As New SUM_Schema(msBaseURL, mlDatabaseID)
                .Append(oSum_Schema.Summerize)

                .Append("</td>")
                .Append("</tr>")
            End If

            .Append("</table>")
        End With

        Return oSum.ToString
    End Function
End Class
